/******************************************************************************
 * Copyright (C) 2015  671643387@qq.com
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 *****************************************************************************/

#ifndef UGAME_SYSTEM_THREAD_H_
#define UGAME_SYSTEM_THREAD_H_

#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif

#include <UGame/Platform.h>
#include <UGame/Macros.h>

#if defined(PLATFORM_WINDOWS)
#include <UGame/System/Thread_WIN32.h>
#elif defined(PLATFORM_LINUX) || defined(PLATFORM_APPLE)
#include <UGame/System/Thread_POSIX.h>
#endif

namespace UGame {
namespace System {
    class Runnable;

    class Thread : private ThreadImpl
    {
    public:
        /* Thread priority */
        enum Priority
        {
            PRIO_LOWEST = PRIO_LOWEST_IMPL,
            PRIO_LOW = PRIO_LOW_IMPL,
            PRIO_NORMAL = PRIO_NORMAL_IMPL,
            PRIO_HIGH = PRIO_HIGH_IMPL,
            PRIO_HIGHEST = PRIO_HIGHEST_IMPL
        };
        /* Thread ID */
        typedef ThreadImpl::ID	ID;

        Thread(void) : ThreadImpl() {}
        ~Thread(void) {}


        bool Start(Runnable* _Runnable) { return StartImpl(_Runnable); }
        void Join(void) { JoinImpl(); }
        bool Joinable(void) { return JoinableImpl(); }
        bool SetPriority(int _Priority) { return SetPriorityImpl(_Priority); }
        ID GetID(void) const { return GetIDImpl(); }

        static ID GetCurrentID(void) { return GetCurrentIDImpl(); }
        static void Sleep(long _Milliseconds) { SleepImpl(_Milliseconds); }

    private:
        DISALLOW_COPY_AND_ASSIGN(Thread);
    };

}}

#endif // UGAME_SYSTEM_THREAD_H_
